<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
		<title>活动成员</title>
		<link rel="stylesheet" type="text/css" media="screen" href="{$staticHost}/static/css/base.css" />
		<link rel="stylesheet" type="text/css" media="screen" href="{$staticHost}/static/css/mod.css" />
		<link rel="stylesheet" type="text/css" media="screen" href="{$staticHost}/static/css/list.css?v=2" />
		<link rel="stylesheet" type="text/css" media="screen" href="{$staticHost}/static/css/page.css" />
		<script src="{$staticHost}/static/js/jquery-1.8.3.min.js"></script>
		<script src="{$staticHost}/static/js/js.js"></script>
		<script src="{$staticHost}/static/js/mod.js"></script>
	</head>
	
	<body>
		<div id="hd">
			<ul id="list" class="list-02"></ul>
		</div>
		<script id="member" type="text/html">
			<% for(var i=0; i< result.members.length ;i++) { %>
			<li>
				<!-- <img src="{$staticHost}/static/images/ac01.jpg"> -->
				<img src="<%=result.members[i].header%>">
				<div class="nv <%=result.members[i].nv%>"></div>
				<dl>
					<dt>
						<%=result.members[i].nickname%>
						<i class="level <%=result.members[i].level%>"></i>
						<span><%=result.members[i].add_time%></span>
					</dt>
					<dd>
						总里程：<%=result.members[i].total_mileage%>km
						<span>次数：<%=result.members[i].total_rate%></span>
					</dd>
				</dl>
			</li>
			<%}%>
		</script>
		<script>

		var gid = "{$gid}";
		var aid = "{$aid}";
		var id =0;
		var time = new Date(new Date().getTime());
		time = (time.getFullYear()+"-"+(time.getMonth()+1)+"-"+time.getDate()+" "+time.getHours()+":"+time.getMinutes());

		var downTime = new Date(new Date().getTime());
		downTime = (downTime.getFullYear()+"-"+(downTime.getMonth()+1)+"-"+downTime.getDate()+" "+downTime.getHours()+":"+downTime.getMinutes());
		$(function(){
			Load()
			$.getJSON('{$staticHost}/groupWeb/activityMembers',{'gid': gid, 'aid':aid}, function(data, error) {
				
				var info = data.result.members;
				if(info.length > 0) {
					for(var x in info) {

						var t = new Date(new Date(parseInt(info[x].add_time) * 1000).getTime());
						info[x].add_time =(t.getFullYear()+"."+xs(t.getMonth()+1)+"."+xs(t.getDate())+ " "+xs(t.getHours())+":"+xs(t.getMinutes()));
						function xs(n){ return n<10?("0"+n):n;}

						if(info[x].gender==1){
							var boy = "ico-boy"
							info[x].nv = boy
						}else{
							var girl = "ico-girl"
							info[x].nv = girl
						}
						
						// 判断男女
						if( info[x].levelInfo.level!=1){
							var level = info[x].levelInfo.level
							info[x].level= "level-"+level
						}
						
						// 判断等级
						var width = document.documentElement.clientWidth; 
						if(width<321){
							if( info[x].nickname.length>6){
								info[x].level= "dn"
							}
						}else if(width<376){
							if( info[x].nickname.length>11){
								info[x].level= "dn"
							}
						}else{
							if( info[x].nickname.length>13){
								info[x].level= "dn"
							}
						}
						
					}
				}
				var html = template('member', data);
				document.getElementById('list').innerHTML = html;

			})
		})
		var counter = 0;
	    var num = 0;
	    var pageStart = 0,pageEnd = 0;
		var generatedCount = 0;
		var lis = $("#list li")
		
		function Load(){
			$('#hd').dropload({
			    scrollArea : window,
			    loadDownFn : function(me){
			    	$.ajax({
			            type: 'GET',
						url: '{$staticHost}/groupWeb/activityMembers',
						dataType: 'json',
						data:{aid:aid,gid:gid,id:id},
			            success: function(data){

			            	console.log(id);
			                var result = '';
			                counter++;    
			                pageEnd = num * counter;
			                pageStart = pageEnd - num;
			                if(typeof info == 'undefined') {
								$(".pullUpLabel").html("已加载完毕");
								return;
							}

							if(info.length> 0 ) {
								id = info[info.length-1].id;
								var html = template('member', data);
								$('#list').append(html);
								
				            }else{
				            	$('#pullUpLabel').html("已加载完毕");
				            	me.noData();
				            	me.lock();
				            } 
			                // 为了测试，延迟1秒加载
			                
			                me.noData();
			                me.resetload();
			                
			            },
			            error: function(xhr, type){
			                alert('Ajax error!');
			                // 即使加载出错，也得重置
			                me.resetload();
			            }
			        });
			    }
			});	
		}
		</script>

		<script src="{$staticHost}/static/js/dropload.min.js"></script>
	</body>
{template 'show/web-footer'}
